<template>
	<view>
    <view v-if="auth">
      <!--header-->
      <view class="bg-primary">
        <view class="h3"/>
        <view class="fac px6">
          <u-avatar :src="filter.image(user.avatar)" mode="circle" @click="navto('my/profile')"/>
          <view class="f1 fdc pl5" @click="navto('my/profile')">
            <text v-if="user.nickname" class="fs34 fw4 toe twb">{{user.nickname}}</text>
            <text v-else class="fs30 fw4 toe twb">点击设置昵称</text>
            <text class="fw5 mt4">{{user.mobile}}</text>
          </view>
        </view>
        <view class="h6"/>
      </view>
      <view class="p4">
        <view class="f py6 br4 bgw">
          <view class="f1 fdc fjc fac" @click="navto('notice/index')">
            <u-badge :offset="[0,0]" :count="user.unreadCount" />
            <text class="icon fs46">&#xe78f;</text>
            <text class="pt3">设置</text>
          </view>
          <view class="f1 fdc fjc fac" @click="navto('my/favorite')">
            <image src="/static/my/favi.png" class="w4 h4" />
            <text class="pt3">收藏</text>
          </view>
          <view class="f1 fdc fjc fac" @click="navto('my/focus')">
            <image src="/static/my/focus.png" class="w4 h4" />
            <text class="pt3">关注</text>
          </view>
          <view class="f1 fdc fjc fac" @click="navto('my/history')">
            <image src="/static/my/history.png" class="w4 h4" />
            <text class="pt3">足迹</text>
          </view>
        </view>
        <view class="bgw mt4">
          <view class="fjb px6 py5">
            <image src="/static/my/order.png" class="w3 h3" />
            <view class="f1 fs30 pl4 lh30 fw6">我的订单</view>
            <view class="fs26 fw4 c9" @click="navto('my/order/index')">查看全部<text class="icon fs26 pl1">&#xe813;</text></view>
          </view>
          <view class="f tac py4 c6 px2">
            <view class="f1 fac fdc w15 px2" @click="navto('my/order/index', {state:1})">
              <view class="pr">
                <u-badge v-if="user.todo.pay" :count="user.todo.pay" :offset="[-5, -10]" />
                <image src="/static/my/pay.png" class="w5 h5" />
              </view>
              <text>待支付</text>
            </view>
            <view class="f1 fac fdc w15 px2" @click="navto('my/order/index', {state:2})">
              <view class="pr">
                <image src="/static/my/receive.png" class="w5 h5" />
                <u-badge v-if="user.todo.receive" :count="user.todo.receive" :offset="[-5, -10]" />
              </view>
              <text>待收货</text>
            </view>
            <view class="f1 fac fdc w15 px2" @click="navto('my/order/index', {state:3})">
              <view class="pr">
                <u-badge v-if="user.todo.comment" :count="user.todo.comment" :offset="[-5, -10]" />
                <image src="/static/my/comment.png" class="w5 h5" />
              </view>
              <text>待评价</text>
            </view>
            <view class="f1 fac fdc w15 px2" @click="navto('my/refund/index')">
              <view class="pr">
                <u-badge v-if="user.todo.refund" :count="user.todo.refund" :offset="[-5, -10]" />
                <image src="/static/my/service.png" class="w5 h5" />
              </view>
              <text>退款/售后</text>
            </view>
          </view>
        </view>
        <view class="f mt4 py4 bgw px2">
          <view class="f1 px2" @click="change('store')">
            <view class="fdc fac py5 bg-page">
              <image src="/static/my/shop.png" class="w5 h5" />
              <view class="mt3">体验店</view>
            </view>
          </view>
          <view class="f1 px2" @click="change('supplier')">
            <view class="fdc fac py5 bg-page">
              <image src="/static/my/supplier.png" class="w5 h5" />
              <view class="mt3">供应商</view>
            </view>
          </view>
          <view class="f1 px2" @click="change('agent')">
            <view class="fdc fac py5 bg-page">
              <image src="/static/my/agent.png" class="w5 h5" />
              <view class="mt3">合伙人</view>
            </view>
          </view>
          <view class="f1 px2" @click="change('courier')">
            <view class="fdc fac py5 bg-page">
              <image src="/static/my/courier.png" class="w5 h5" />
              <view class="mt2">骑手</view>
            </view>
          </view>
        </view>
        <view class="mt4 px6 bgw">
          <view class="fjb py5 bt" @click="navto('my/address/index')">
            <image src="/static/my/address.png" class="w4 h4" />
            <view class="f1 pl4">地址管理</view>
            <u-icon name="arrow-right" color="#999" />
          </view>
          <view class="fjb py5 bt" @click="navto('help/index')">
            <image src="/static/my/question.png" class="w4 h4" />
            <view class="f1 pl4">常见问题</view>
            <u-icon name="arrow-right" color="#999" />
          </view>
          <view class="fjb py5 bt" @click="navto('my/feedback/index')">
            <image src="/static/my/feedback.png" class="w4 h4" />
            <view class="f1 pl4">意见反馈</view>
            <u-icon name="arrow-right" color="#999" />
          </view>
          <view class="fjb py5 bt" @click="navto('my/expand')">
            <image src="/static/my/expand.png" class="w4 h4" />
            <view class="f1 pl4">拓展用户</view>
            <u-icon name="arrow-right" color="#999" />
          </view>
          <view class="fjb py5 bt" v-if="is_admin" @click="navto('plat/index')">
            <image src="/static/my/plat.png" class="w4 h4" />
            <view class="f1 pl4">管理平台</view>
            <u-icon name="arrow-right" color="#999" />
          </view>
        </view>
      </view>
    </view>
    <view v-else class="bg-primary h20 fac">
      <view class="wt fac px6">
        <u-avatar :src="filter.image($store.user.avatar)" mode="circle" />
        <view class="px6" @click="$store.main.update({showAuth: true})">登录/注册</view>
      </view>
    </view>
		<view class="mt3 p2" v-if="auth && list.length>0">
			<u-divider fontSize="36"><text class="py5">为你推荐</text></u-divider>
			<view class="fww">
				<view v-for="(item, i) in list" :key="i" class="fdc mb2 bgw br2 col-2" @click="navto('item/view', { id: item.id || item._id })">
					<image :lazy-load="true" :src="filter.image(item.thumb)" class="wt h36 fade-in" mode="widthFix" />
					<view class="f1 px4 fs26 tl2">【{{filter.country(item.home)}}】{{item.name}}{{item.spec}}</view>
					<view class="pt2 px4 tsn c9">进价{{filter.number(item.cost / 10000)}}+利润{{filter.number(item.price/100 - item.cost / 10000)}}</view>
					<view class="py2 px4 fjb">
						<view class="fc-primary fs34">
							<text class="fs20">￥</text>
							<text>{{filter.number( item.price/100)}}</text>
						</view>
						<view @click.stop="item_id=item.id">
							<u-icon name="shopping-cart" size="36" />
						</view>
					</view>
				</view>
			</view>
		</view>

		<Tabbar :activeKey="4" />
	</view>
</template>

<script lang="ts">
import util from '@/utils/util'
import {page} from '@/mixins'
// import app from '@/config/app'
import Tabbar from './Tabbar'
export default {
	mixins: [page],
	components: {Tabbar},
	data() {
		return {
			meta: {title: '用户中心'},
			item_id: 0,
			list: [],
			is_admin: false,
			user: uni.$store.user
		}
	},
	onLoad() {
		this.loadPath = this.auth ? 'my' : 'index/hots'
	},
	methods: {
		loadData(res){
			this.list = res.list
			this.is_admin = res.is_admin
			Object.assign(this.user.todo, res.todo)
		},
		change(type = 'store'){
			uni.$store.main.update({idtype: type})
			uni.$u.http.get(type + '/profile').then(res=>{
				uni.$store[type].update(res)
				util.navto(type + '/index')
			}).catch(()=>{})
		}
		/*
		timLogin(type, res){
			uni.$tim.login({
				userID: type + res.id,
				userSig: res.timsig
			}).then(()=>{
				util.navto(type + '/index')	
			})
		}
		*/
	}
}
</script>
